﻿using RemoteTestRunner.BusinessLogic;
using RemoteTestRunner.Contracts;

namespace RemoteTestRunner.ServiceFacade
{
    /// <summary>
    /// Specifies the type of service object to be used.
    /// </summary>
    public enum ServiceType
    {
        /// <summary>
        /// Specifies a client-side service will be used.
        /// </summary>
        ClientService,

        /// <summary>
        /// Specifies a server-side service will be used.
        /// </summary>
        ServerService
    }

    public static class ServiceFactory
    {

        static ServiceFactory()
        {
            IoC.Container.RegisterType<IRTRService, RtrLib>("local");
            //IoC.Container.RegisterType<RTRService.IRTRService, ServerFacade>("remote");
        }

        /// <summary>
        /// Gets the appropriate service object based on the requested type.
        /// </summary>
        /// <param name="serviceType">Type of the service object to be created.</param>
        /// <returns>An instance of <see cref="IRTRService"/> for the requested
        /// service type.</returns>
        public static IRTRService GetServiceObject(ServiceType serviceType)
        {

            switch (serviceType)
            {
                case ServiceType.ClientService:
                    return IoC.Container.Resolve<IRTRService>("local");
                    //return new RtrLib();
                case ServiceType.ServerService:
                    return IoC.Container.Resolve<IRTRService>("remote");
                    //return new ServerFacade();
                default:
                    return null;
            }
        }

        /// <summary>
        /// Gets the appropriate service object based on the requested type.
        /// </summary>
        /// <param name="serviceUrl">The URL of the WCF service being utilized.</param>
        /// <param name="timeoutSeconds">The timeout seconds.</param>
        /// <returns>
        /// An instance of <see cref="IRTRService"/> for the requested
        /// service type.
        /// </returns>
        public static IRTRService GetServiceObject(string serviceUrl, int timeoutSeconds)
        {
            return new ServerFacade(serviceUrl, timeoutSeconds);
        }
    }
}
